package com.csc.mtlbatch.util;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ClsResourceUtil extends org.springframework.core.io.FileSystemResource {
	
	private static String fileLocation ="";
	private static String filePathLocation = "";
	private static String dateStamp ="";
	
	public static String getFileLocation() {
		return fileLocation;
	}

	public static void setFileLocation(String fileLocation) {
		ClsResourceUtil.fileLocation = fileLocation;
	}

	public static String getFilePathLocation() {
		return filePathLocation;
	}

	public static void setFilePathLocation(String filePathLocation) {
		ClsResourceUtil.filePathLocation = filePathLocation;
	}

	public static String getDateStamp() {
		return dateStamp;
	}

	public static void setDateStamp(String dateStamp) {
		ClsResourceUtil.dateStamp = dateStamp;
	}

	public ClsResourceUtil(File file) {
		super(outputFile(file));
		// TODO Auto-generated constructor stub
	}
	
	private static File outputFile(File file){

		String strFilename = getfileName(file);
		String strFilePath = file.getAbsolutePath().replace(file.getName(), strFilename);
		setFileLocation(strFilename);
		setFilePathLocation(strFilePath);
		
		return new File(strFilePath);
	}
	
	private static String getfileName(File file){
		return file.getName() + getDateStampFormat() + getTimeStampFormat() + ".dat";
	}
	
	private static String getDateStampFormat(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		Date now = new Date();
	    String strDate = sdf.format(now);
	    setDateStamp(strDate);
		return strDate;
	}
	
	private static String getTimeStampFormat(){
		SimpleDateFormat sdf = new SimpleDateFormat("HHmmssSSS");
		Date now = new Date();
	    String strTime = sdf.format(now);
		return strTime;
	}
	
}
